package io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

public class Test08 {

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        // 被复制的文件
        File fromFile = new File("D:/1.txt");
        // 复制出来的文件
        File toFile = new File("D:/5.txt");
        Reader reader = null;
        Writer writer = null;
        BufferedReader br = null;
        BufferedWriter bw = null;
        try {
            reader = new FileReader(fromFile);
            writer = new FileWriter(toFile);
            br = new BufferedReader(reader);
            bw = new BufferedWriter(writer);
            String content = br.readLine();//读取一行
            while (content != null) {
                bw.write(content);
                // 换行操作
                bw.newLine();
                bw.flush();
                content = br.readLine();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        long endTime = System.currentTimeMillis();
        System.out.println("文件复制完成,耗时:" + (endTime - startTime) + "毫秒");

    }

}